package at.fhooe.tof.bl;

import at.fhooe.tof.app.Observer;

public class PlayInstrument {
	private PlayTone playTone = new PlayTone();
	
	public void playSound(float minR, float minL, int minRX, int minRY, int minLX, int minLY){
		if(ConditionCheck.checkStartDistance(minR) 
				|| ConditionCheck.checkStartDistance(minL)){
			float distRightHand = calculateDistance(minRX, minRY, true);
			float distLeftHand = calculateDistance(minLX, minLY, false);
			Observer.sendMsg("frequency"+distRightHand);
			Observer.sendMsg("amplitude"+distLeftHand);
			playTone.play(distRightHand, distLeftHand);
			System.out.println("RH dist: "+minR+"|"+String.valueOf(distRightHand)+" - "+minRX+";"+minRY+";"+minLX+";"+minLY);
			System.out.println("LH dist: "+minL+"|"+String.valueOf(distLeftHand));
		} else {
			playTone.stopPlaying();
		}
		
	}
	
	public float calculateDistance(int x, int y, boolean isRightHand){
		float result;
		if(isRightHand==true)
			result = (float) Math.sqrt(Math.pow(ReferencePoints.rightX-x,2)+Math.pow(ReferencePoints.rightY-y, 2));
		else
			result = ReferencePoints.leftY - y;
			//result = (float) Math.sqrt(Math.pow(ReferencePoints.leftX-x,2)+Math.pow(ReferencePoints.leftY-y, 2));
		return result;
	}
}
